import java.awt.Color;


public class ItemBoxed {
	public String item_number; // 128a for nendoroid 128a
	public String name;
	
	public Color general;
	public Color borderone;
	public Color bordertwo;
	
	public ItemBoxed(String num, String n){
		this.item_number = num;
		this.name = n;
		this.setAllColor("000000", "000000", "000000");
	}
	
	public ItemBoxed(){}
	
	public void setColor(int a,String c){
		switch(a){
			case 0 : this.general = colorToHex(c);
			case 1 : this.borderone = colorToHex(c);
			case 2 : this.bordertwo = colorToHex(c);
		}
	}
	
	public void setAllColor(String a, String b, String c){
		setColor(0,a);
		setColor(1,b);
		setColor(2,c);
	}
	
	public void setName(String n){
		this.name = n;
	}
	
	public void setNumber(String num){
		this.item_number = num;
	}
	
	public Color getColor(int a){
		switch(a){
		case 0 : return general;
		case 1 : return borderone;
		case 2 : return bordertwo;
		}
		return null;
	}

	public String getName(){
		return name;
	}
	
	public String getItemNum(){
		return item_number;
	}

	
	
	private static final char[] HEX_CHARS = "0123456789ABCDEF".toCharArray();
	
	public Color colorToHex(String c){
		assert(c.length() <= 6);
		char[] c_arr = c.toUpperCase().toCharArray();
		int i = 0;
		if(c.startsWith("#")) i = 1;
		return new Color((getCharPosition(c_arr[i])*16+getCharPosition(c_arr[i+1])),
						 (getCharPosition(c_arr[i+2])*16+getCharPosition(c_arr[i+3])),
						 (getCharPosition(c_arr[i+4])*16+getCharPosition(c_arr[i+5])));
	}
	
	public String hexToColor(int a){
		Color tmp = this.getColor(a);
		return hexToColor(tmp);
	}
	
	public String hexToColor(Color a){
		String hex = "#"+(getCharPosition(a.getRed()/16))+(getCharPosition(a.getRed()%16))
						+(getCharPosition(a.getGreen()/16))+(getCharPosition(a.getGreen()%16))
						+(getCharPosition(a.getBlue()/16))+(getCharPosition(a.getBlue()%16));
		return hex;
	}

	public int getCharPosition(char c){
		int i = 0;
		while(i<16){
			if(c == HEX_CHARS[i]) break;
			else i++;
		}
		return i;
	}
	
	public char getCharPosition(int i){
		return HEX_CHARS[i];
	}
	
	
	
	public void testCP(char[] a){
		for(int i=0; i < a.length; i = i+2)
			System.out.print((a[i])+""+(a[i+1])+"\t = \t"+(getCharPosition(a[i])*16+getCharPosition(a[i]))+"\n");
	}

	public String toString(){
		return "["+this.item_number+"]\t "+this.name;
	}
}
